package com.hong.demo.other.flink;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

public class SumTest {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<Integer> stream = env.fromCollection(Arrays.asList(1, 4, 6, 3, 2, 5));

        KeyedStream<Integer, Boolean> keyBy = stream.keyBy(number -> number > 3);

        SingleOutputStreamOperator<Integer> max = keyBy.sum(0);

        max.print();

        env.execute();
    }
}
